﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Web;

namespace INNOVACALL.Framework.Common.MVCHelpers.DataAnnotations
{
    public class CustomAttr_StringLength : StringLengthAttribute
    {

        public CustomAttr_StringLength(int maximumLength) : base(maximumLength) {
        }
        
        /// <summary>
        /// Message d'erreur personnalisé, passer une chaine séparée par des ;
        /// </summary>
        /// <param name="name">
        /// [0] ResourceType
        /// [1] ResourceName
        /// [2] CustomParam
        /// </param>
        /// <returns></returns>
        public override string FormatErrorMessage(string name)
        {
            string[] sParams = name.Split(';');
            string sResourceType = sParams[0];
            string sResourceName = sParams[1];
            string toReturn = string.Format((String)HttpContext.GetGlobalResourceObject(base.ErrorMessageResourceType.Name, base.ErrorMessageResourceName),base.MaximumLength);
            return toReturn;
        }
    }
}
